package net.maku.generator.controller;

import lombok.AllArgsConstructor;
import net.maku.generator.domain.query.Query;
import net.maku.generator.common.utils.Result;
import net.maku.generator.domain.entity.TemplateEntity;
import net.maku.generator.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模板管理
 */
@RestController
@RequestMapping("maku-generator/gen/template")
@AllArgsConstructor
public class TemplateController {

    @Autowired
    private TemplateService templateService;

    /**
     * 模板列表
     */
    @GetMapping("list")
    public Result<List<TemplateEntity>> list(Query query) {
        return Result.ok(templateService.list(query));
    }

    /**
     * 新增模板
     */
    @PostMapping("add")
    public Result<Void> add(@RequestBody TemplateEntity template) {
        templateService.add(template);
        return Result.ok();
    }

    /**
     * 模板详情
     */
    @GetMapping("{id}")
    public Result<TemplateEntity> get(@PathVariable("id") Long id) {
        TemplateEntity template = templateService.getById(id);
        return Result.ok(template);
    }

    /**
     * 修改模板
     */
    @PutMapping("update")
    public Result<Void> update(@RequestBody TemplateEntity template) {
        templateService.update(template);
        return Result.ok();
    }

    /**
     * 删除模板
     */
    @DeleteMapping("delete")
    public Result<Void> delete(@RequestBody List<Long>  idList) {
        templateService.deleteBatchIds(idList);
        return Result.ok();
    }

}
